﻿using System.Threading.Tasks;
using Magicodes.ExporterAndImporter.Excel.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NP.BPMReportPlatform.UserTrial.Dto;
using Volo.Abp.Application.Dtos;

namespace NP.BPMReportPlatform.UserTrial
{
    /// <summary>
    /// 工程接口
    /// </summary>
    [Authorize]
    [ApiController]
    [Route("api/user-trial")]
    public class UserTrialController : BPMReportPlatformController
    {
        private readonly IUserTrialService _userTrialService;

        public UserTrialController(IUserTrialService userTrialService)
        {
            _userTrialService = userTrialService;
        }

        /// <summary>
        /// 试用期员结果汇总查询数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("SR/GetSummarResultAsync")]
        public async Task<PagedResultDto<GetSummarResultOutput>> GetAllAsync([FromBody] GetSummarResultInput input)
        {
            return await _userTrialService.GetSummarResult(input);
        }

        /// <summary>
        /// 导出试用期结果汇总表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("SR/ExportAsync")]
        public async Task<FileResult> ExportSummarResultAsync ([FromBody] GetSummarResultInput input)
        {
            var rst = await _userTrialService.ExportSummarResultAsync(input);
            string downloadFileName = System.Guid.NewGuid().ToString("N") + ".xlsx";
            rst.Close();
            return File(rst.ToArray(), "application/octet-stream", $"{downloadFileName}.xlsx");
        }

        /// <summary>
        /// 根据工号查询员工适期情况明细表
        /// </summary>
        /// <param name="workNumber">工号</param>
        /// <returns></returns>
        [HttpGet]
        [Route("SR/GetSummarResultDetailAsync")]
        public async Task<SummarResultDetail> GetSummarResultDetailAsync([FromQuery] string workNumber)
        {
            return await _userTrialService.GetSummarResultDetailAsync(workNumber);
        }

        /// <summary>
        /// 根据工号导出员工适期情况明细表
        /// </summary>
        /// <param name="workNumber">工号</param>
        /// <returns></returns>
        [HttpGet]
        [Route("SR/ExportSummarResultDetailAsync")]
        public async Task<FileResult> ExportSummarResultDetailAsync([FromQuery] string workNumber)
        {
            var rst = await _userTrialService.ExportSummarResultDetailAsync(workNumber);
            string downloadFileName = System.Guid.NewGuid().ToString("N") + ".xlsx";
            rst.Close();
            return File(rst.ToArray(), "application/octet-stream", $"{downloadFileName}.xlsx");
        }


        /// <summary>
        /// 适用期转正评估明细查询数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("RD/GetRegularResultAsync")]
        public async Task<PagedResultDto<GetRegularDetailOutput>> GetRegularResult([FromBody] GetSummarResultInput input)
        {
            return await _userTrialService.GetRegularResultAsync(input);
        }

        /// <summary>
        /// 导出适用期转正评估明细
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("RD/ExportAsync")]
        public async Task<FileResult> ExportRegularResult([FromBody] GetSummarResultInput input)
        {
            var rst = await _userTrialService.ExportRegularResultAsync(input);
            string downloadFileName = System.Guid.NewGuid().ToString("N") + ".xlsx";
            rst.Close();
            return File(rst.ToArray(), "application/octet-stream", $"{downloadFileName}.xlsx");
        }


        /// <summary>
        /// 查询试用期月度评估明细表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("TD/GetAllAsync")]
        public async Task<PagedResultDto<GetTrialDetailOutput>> GetTrialDetailAsync([FromBody] GetSummarResultInput input)
        {
            return await _userTrialService.GetTrialDetailAsync(input);
        }

        /// <summary>
        /// 导出试用期月度评估明细表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("TD/ExportTrialDetailAsync")]
        public async Task<FileResult> ExportAsync([FromBody] GetSummarResultInput input)
        {
            var rst = await _userTrialService.ExportTrialDetailAsync(input);
            string downloadFileName = System.Guid.NewGuid().ToString("N") + ".xlsx";
            rst.Close();
            return File(rst.ToArray(), "application/octet-stream", $"{downloadFileName}.xlsx");
        }


        /// <summary>
        /// IU转正回传结果 查询数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("GE/GetGeneralResultAsync")]
        public async Task<PagedResultDto<GetGeneralResultOutput>> GetGeneralResultAsync([FromBody] GetSummarResultInput input)
        {
            return await _userTrialService.GetGeneralResultAsync(input);
        }


        /// <summary>
        /// IU转正回传结果 导出数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("GE/ExportGeneralResultAsync")]
        public async Task<XlsxFileResult<GetGeneralResultOutput>> ExportGeneralResultAsync([FromBody] GetSummarResultInput input)
        {
            var rst = await _userTrialService.ExportGeneralResultAsync(input);
            return new XlsxFileResult<GetGeneralResultOutput>(rst, "导出Excel");
        }


        ///// <summary>
        ///// 一体板订单取消变更流程  查询数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("YTBOrder/GetAllAsync")]
        //public async Task<PagedResultDto<GetYTBOrderOutput>> GetAllAsync(
        //    [FromBody] GetYTBOrderInput input)
        //{
        //    return await _gCAppService.GetAllAsync(input);
        //}


        ///// <summary>
        ///// 一体板订单取消变更流程  导出数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("YTBOrder/ExportAsync")]
        //public async Task<XlsxFileResult<GetYTBOrderOutput>> ExportAsync(
        //    [FromBody] GetYTBOrderInput input)
        //{
        //    var rst = await _gCAppService.ExportAsync(input);
        //    return new XlsxFileResult<GetYTBOrderOutput>(rst, "导出Excel");
        //}

        ///// <summary>
        ///// 新工程取消订单  查询数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("GCQXDD/GetAllAsync")]
        //public async Task<PagedResultDto<GetEngineeringBatchCancelOrdersOutput>> GetAllAsync(
        //    [FromBody] GetEngineeringBatchCancelOrdersInput input)
        //{
        //    return await _gCAppService.GetAllAsync(input);
        //}


        ///// <summary>
        ///// 新工程取消订单  导出数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("GCQXDD/ExportAsync")]
        //public async Task<XlsxFileResult<GetEngineeringBatchCancelOrdersOutput>> ExportAsync(
        //    [FromBody] GetEngineeringBatchCancelOrdersInput input)
        //{
        //    var rst = await _gCAppService.ExportAsync(input);
        //    return new XlsxFileResult<GetEngineeringBatchCancelOrdersOutput>(rst, "导出Excel");
        //}


        ///// <summary>
        ///// 一体板加急生产申请流程  查询数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("YTBJJSCSQ/GetAllAsync")]
        //public async Task<PagedResultDto<GetYTBUrgentApplicationOutput>> GetAllAsync(
        //    [FromBody] GetYTBUrgentApplicationInput input)
        //{
        //    return await _gCAppService.GetAllAsync(input);
        //}


        ///// <summary>
        ///// 一体板加急生产申请流程  导出数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("YTBJJSCSQ/ExportAsync")]
        //public async Task<XlsxFileResult<GetYTBUrgentApplicationOutput>> ExportAsync(
        //    [FromBody] GetYTBUrgentApplicationInput input)
        //{
        //    var rst = await _gCAppService.ExportAsync(input);
        //    return new XlsxFileResult<GetYTBUrgentApplicationOutput>(rst, "导出Excel");
        //}


        ///// <summary>
        ///// 一体板产品色号维护申请表  查询数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("YTBCPSHWHSQB/GetAllAsync")]
        //public async Task<PagedResultDto<GetYTBCPSHWHSQBOutput>> GetAllAsync(
        //    [FromBody] GetYTBCPSHWHSQBInput input)
        //{
        //    return await _gCAppService.GetAllAsync(input);
        //}


        ///// <summary>
        ///// 一体板产品色号维护申请表  导出数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("YTBCPSHWHSQB/ExportAsync")]
        //public async Task<XlsxFileResult<GetYTBCPSHWHSQBOutput>> ExportAsync(
        //    [FromBody] GetYTBCPSHWHSQBInput input)
        //{
        //    var rst = await _gCAppService.ExportAsync(input);
        //    return new XlsxFileResult<GetYTBCPSHWHSQBOutput>(rst, "导出Excel");
        //}



        ///// <summary>
        ///// 账期调整流程  查询数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("AccountPeriodAdjustmentApplication/GetAllAsync")]
        //public async Task<PagedResultDto<GetAccountPeriodAdjustmentApplicationOutput>> GetAllAsync(
        //    [FromBody] GetAccountPeriodAdjustmentApplicationInput input)
        //{
        //    return await _gCAppService.GetAllAsync(input);
        //}


        ///// <summary>
        ///// 账期调整流程  导出数据
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("AccountPeriodAdjustmentApplication/ExportAsync")]
        //public async Task<XlsxFileResult<GetAccountPeriodAdjustmentApplicationOutput>> ExportAsync(
        //    [FromBody] GetAccountPeriodAdjustmentApplicationInput input)
        //{
        //    var rst = await _gCAppService.ExportAsync(input);
        //    return new XlsxFileResult<GetAccountPeriodAdjustmentApplicationOutput>(rst, "导出Excel");
        //}
    }
}